package com.example05;

import com.example05.entity.*;
import com.example05.resource.DatabaseUtils;
import java.util.List;
import java.util.Optional;

public class Test {
    public static void main(String[] args) {
        //getCollegeName(DatabaseUtils.listStudents().get(2));
        //isTeacher(DatabaseUtils.listStudents().get(2), "曾志优");
        //System.out.println(getCollegeName(DatabaseUtils.listStudents(),201001));
        //printCollegeName(DatabaseUtils.listStudents(), 201001, 1002);
    }
    private static void getCollegeName(Student student) {
         Optional.ofNullable(student)
                .map(Student::getTeacher)
                .map(Teacher::getCollege)
                .ifPresentOrElse(college -> System.out.println(college.getName()), () -> System.out.println("未知学院"));
    }
    private static void isTeacher(Student student, String teacherName) {
        Optional.ofNullable(student)
                .map(Student::getTeacher)
                .filter(s -> s.getName().equals(teacherName))
                .ifPresentOrElse(s -> System.out.println("true"), () ->System.out.println("false"));
    }
    private static String getCollegeName(List<Student> students, int sNumber) {
        return students.stream()
                .filter(student -> student.getNumber() == sNumber)
                .findFirst()
                .map(Student::getTeacher)
                .map(Teacher::getCollege)
                .map(College::getName)
                .orElse("未知学院");

    }
    private static void printCollegeName(List<Student> students, int sNumber, int tNumber) {
        students.stream()
                .filter(student -> student.getNumber() == sNumber)
                .map(Student::getTeacher)
                .filter(teacher -> teacher.getNumber() == tNumber)
                .findFirst()
                .map(Teacher::getCollege)
                .map(College::getName)
                .ifPresentOrElse(System.out::println, () -> System.out.println("未知学院"));
    }
}
